import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '@/store'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Home,
    name: 'Home',
  },
  {
    path: '/list',
    name: 'List',
    component: () => import('@/views/List.vue'),
  },
  {
    path: '/detail/:id',
    name: 'Detail',
    component: () => import('@/views/Detail.vue'),
  },
]

// History 模式记住缓存组件的滚动位置
/* const router = new VueRouter({
  routes,
  mode: 'history',
  scrollBehavior(to, from, savedPosition) {
    const cachePages = store.state.cachePages
    if (cachePages.includes(to.name)) {
      return savedPosition || { x: 0, y: 0 }
    }
    return { x: 0, y: 0 }
  },
}) */

const router = new VueRouter({
  routes,
})
export default router
